﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.mMall.Seller
{
	public partial class mfOrderInfo : msBsc.Cls.mBPDealer
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}
        private void getOrder()
        {
            string orderId = this.GetParamHtValue("orderId");
            if (string.IsNullOrEmpty(orderId))
            {
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizDJkOrdersDetail orderInfo = new AppLogic.DataAlc.CBizDJkOrdersDetail())
            {
                DataSet ds = orderInfo.GetOrderDetailsById(orderId, true);
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "ORDERS_INFO_ID,ORDER_TIME,ORDER_CODE,ORDER_STATUS,ORDER_START_TIME,ORDER_STOP_TIME,ORDER_TOTAL_BALANCE,DISCOUNT_AMT,PAID_AMT,CUSTOMER_REGISTER_ID,CUSTOMER_NICK,CUSTOMER_DEFAULT_PIC,DEPOSIT_RATIO,PAYABLE_AMT,PAYABLE_TOTAL_AMT", 1, 100, "");
                this.ExecJScript("setOrder(" + ret + ")");
            }
        }

        //确认订单
        private void okOrder() 
        {
            string orderId = this.GetParamHtValue("orderId");
            if (string.IsNullOrEmpty(orderId))
            {
                this.Alert("请选择订单");
                return;
            }
            string djakcId=msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(djakcId))
            {
                //页面跳转
                this.Alert("请登录");
                this.ExecJScript(@"window.location.reload()");
            }
            using (msBsc.AppLogic.DataAlc.CBizOrdersInfo orderInfo=new AppLogic.DataAlc.CBizOrdersInfo())
            {
                string[] ret = orderInfo.UpdateDjkOrderStatus(djakcId,orderId,msBsc.AppLogic.DataAlc.OrderStatusEnum.SolderChecked);
                if (ret[0] != "true")
                {
                    this.Alert(ret[1]);
                }
                else
                {
                    //页面跳转
                    this.ExecJScript(@"alert('订单确认成功');window.location.reload()");
                }
            }
        }

        /// <summary>
        /// 删除订单
        /// </summary>
        /// Author:任延华
        /// Creation date:2015-07-27
        private void deleteOrder()
        {
            string orderId = this.GetParamHtValue("orderId");
            if (string.IsNullOrEmpty(orderId))
            {
                this.Alert("请选择订单");
                return;
            }
            string djakcId = msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(djakcId))
            {
                //页面跳转
                this.Alert("请登录");
                this.ExecJScript(@"window.location.reload()");
            }
            using (msBsc.AppLogic.DataAlc.CBizOrdersInfo orderInfo = new AppLogic.DataAlc.CBizOrdersInfo())
            {
                string ret = orderInfo.DeleteOrder(djakcId, orderId, true);
                if (ret != "OK")
                {
                    this.Alert(ret);
                }
                else
                {
                    //页面跳转
                    this.Alert("删除成功");
                    this.ExecJScript(@"window.location.reload()");
                }
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                getOrder();
            }
            else if (this.strAction=="okOrder")
            {
                okOrder();
            }
            else if (this.strAction == "deleteOrder")
            {
                deleteOrder();
            }
        }
	}
}